﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zero.UControl.Component.MsgBox
{
    public class MsgBoxManager
    {
        private static Dictionary<MsgType, string> IconDict;

        static MsgBoxManager()
        {
            IconDict = new Dictionary<MsgType, string>()
            {
                { MsgType.INFO,"pack://application:,,,/Zero.UControl.Assets;component/Imgs/Tips/info.png" },
                { MsgType.WARNING,"pack://application:,,,/Zero.UControl.Assets;component/Imgs/Tips/warn.png" },
                { MsgType.ERROR,"pack://application:,,,/Zero.UControl.Assets;component/Imgs/Tips/error.png" },
            };
        }

        public static void ShowMsgBox(string message, string title, MsgType msgType = MsgType.INFO, Action<bool> action = null)
        {
            if (!IconDict.ContainsKey(msgType))
                throw new Exception("选择的消息类型不存在");
            UMessageBox msgBox = new UMessageBox();
            msgBox.DialogTitle = title;
            msgBox.IconPath = IconDict[msgType];
            msgBox.Message = message;
            msgBox.DoAction = action;
            msgBox.ShowDialog();
        }

        public static void Info(string message, string title = "提示", Action<bool> action = null)
        {
            ShowMsgBox(message, title, MsgType.INFO, action);
        }

        public static void Warn(string message, string title = "警告", Action<bool> action = null)
        {
            ShowMsgBox(message, title, MsgType.WARNING, action);
        }

        public static void Error(string message, string title = "错误", Action<bool> action = null)
        {
            ShowMsgBox(message, title, MsgType.ERROR, action);
        }
    }

    public enum MsgType
    {
        INFO,
        WARNING,
        ERROR
    }
}
